package com.laihuichuxing.mq.consumerRocket;

import com.alibaba.fastjson.JSON;
import com.laihuichuxing.order.handle.UserHandler4Mongo;
import com.laihuichuxing.pool.dto.UserLbsDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.starter.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.starter.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Description:
 *
 * @author: Qinxuefeng
 * @since: 1.0
 * Create Date Time: 2018/10/17 14:15
 * Update Date Time:
 */
@Slf4j
@Service
@RocketMQMessageListener(topic = "userCancelTopic", consumerGroup = "${spring.rocketmq.userCancelGroup}")
public class UserCancelRConsumer implements RocketMQListener<Map>{
    @Autowired
    private UserHandler4Mongo userHandle;
    @Override
    public void onMessage(Map map) {
        try {
            String orderId=map.get("orderId").toString();
            map.remove("orderId");
            UserLbsDto userLbsDto = JSON.parseObject(JSON.toJSONString(map), UserLbsDto.class);
            userHandle.shutdown(userLbsDto,orderId);

        } catch (Exception e) {
            log.error("用户取消订单异常:{}",e.toString(),e);
        }
    }
}